﻿using System;
using System.Collections.Generic;

namespace Unity.Credentials
{
    public class UnityCredentials
    {
        private static UnityCredentials Instance;

        private UnityCredentials()
        {
        }

        public static UnityCredentials GetInstance()
        {
            return Instance ?? (Instance = new UnityCredentials());
        }

        public static readonly string PropertyNameSslTruststore     = "ssl.truststore.file";
        public static readonly string PropertyNameSslTruststorePass = "ssl.truststore.password";
        public static readonly string PropertyNameSslTruststoreType = "ssl.truststore.type";
        public static readonly string PropertyNameSslKeystore       = "ssl.keystore.file";
        public static readonly string PropertyNameSslKeystorePass   = "ssl.keystore.password";
        public static readonly string PropertyNameSslKeystoreType   = "ssl.keystore.type";
        public static readonly string PropertyNameSslKeystoreKeyPass = "ssl.keystore.key.password";

        public static readonly string PropertyNameEnvironmentName = "environment";
        public static readonly string PropertyNameCsiId = "csi.id";


        public static readonly string EnvironmentParameterNameSslTruststore     = "SSL_Truststore";
        public static readonly string EnvironmentParameterNameSslTruststoreDir  = "SSL_Truststore_DIR";
        public static readonly string EnvironmentParameterNameSslTruststorePass   = "SSL_Truststore_PASS";
        public static readonly string EnvironmentParameterNameSslTruststoreType   = "SSL_Truststore_TYPE";
        public static readonly string EnvironmentParameterNameSslKeystore       = "SSL_KEYSTORE";
        public static readonly string EnvironmentParameterNameSslKeystorePass   = "SSL_KEYSTORE_PASS";
        public static readonly string EnvironmentParameterNameSslKeystoreType   = "SSL_KEYSTORE_TYPE";
        public static readonly string EnvironmentParameterNameSslKeystoreKeyPass = "SSL_KEYSTORE_KEYPASS";

        public static readonly string EnvironmentParameterNameEnvironmentName = "ENVIRONMENT";
        public static readonly string EnvironmentParameterNameCsiId = "CSI_ID";

        public class StoreType
        {
            private readonly string type;

            public StoreType(string type)
            {
                this.type = type;
            }

            public string Type
            {
                get; set;
            }
        }
        public static readonly StoreType PEM = new StoreType("PEM");
        public static readonly StoreType JKS = new StoreType("JKS");
        public static readonly StoreType PKCS12 = new StoreType("PKCS12");

        static List<StoreType> ValidStoreTypes = new List<StoreType>
        {
            JKS, PEM, PKCS12
        };


        public static UnityCredentials FromDefault(DefaultType type)
        {
            return FromDefault(type, true);
        }

        public static UnityCredentials FromDefault(DefaultType type, bool isDebug)
        {
            throw new NotSupportedException();
        }
    }
}
